home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: my program has a mind of its own (no really)
- Date: Tue, 09 Apr 96 11:55:31 GMT
- Organization: none
- Message-ID: <829050931snz@genesis.demon.co.uk>
- References: <sbb-0904960305370001@ts13-06.upenn.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <sbb-0904960305370001@ts13-06.upenn.edu>
- sbb@eniac.seas.upenn.edu "Steve Bronstein" writes:
-
- >I am writing a program (with cc as compiler) which has a number of arrays,
- >which I have been verry careful to initialize with values, to avoid
- >segmentation faults.
-
- Are you talking about arrays of pointers here? What did you initialise
- the arrays with and how are you using them? In short post some code so we
- can see what you are actually doing.
-
- The main part of the program is a loop beginning with
- >an fgets statement to read in the next line from a file. Under certain
- >circumstances, the program returns "Segmentation Fault" just as it reaches
- >the beginning of this loop. When I put it a printf statement right before
- >the loop to see how far it actually got, it worked.
-
- You've done something bad with pointers e.g. used an uninitialised one,
- dereferenced one that doesn't point to a writable object or gone out of
- bounds on pointer arithmetic.
-
- >printf("something\n");
- >
- >When I removed "something", leaving just
- >
- >printf("\n");
- >
- >it gave me a segmentation fault again. I tried the same tactic at the
- >beginning of the loop, and found that the program worked with a long word
- >in the printf statement, but not a short word.
-
- Slight variations of the layout of memory may mask the problem but it is
- still there.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-